import { WinstonLogger } from 'nest-winston';

export class CustomTypeOrmLogger {
  constructor(private winstonLogger: WinstonLogger) {}

  log(level: 'log' | 'info' | 'warn', message: any) {
    this.winstonLogger.log(
      `Mapped {Level:${level} Message: ${message} } Message`,
      'TypeORM',
    );
  }

  logQuery(query: string) {
    this.winstonLogger.log(`Mapped {Query: ${query} } SQL`, 'TypeORM');
  }

  logQueryError(error: string | Error, query: string) {
    this.winstonLogger.error(`Mapped {Query: ${query} } SQL`, 'TypeORM');
    this.winstonLogger.error(`Mapped {Error: ${error} } Error`, 'TypeORM');
  }

  logQuerySlow(time: number, query: string, parameters?: any[]) {
    this.winstonLogger.error(`Mapped {Query: ${query} } SQL`, 'TypeORM');
    this.winstonLogger.log(
      `Mapped {Params: ${parameters} ,Duration: ${time}ms} Params`,
      'TypeORM',
    );
  }

  logSchemaBuild(message: string) {
    this.winstonLogger.log(`Mapped {Message: ${message} } Message`, 'TypeORM');
  }

  logMigration(message: string) {
    this.winstonLogger.log(`Mapped {Message: ${message} } Message`, 'TypeORM');
  }
}
